﻿using POC.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace wlog.Shell.IO
{
    public class SetVariableCommand : Command
    {
        string keyval;
        public override void Setup(string[] args)
        {
            CommandArgs = args;
            this.CommnadName = args[0].Trim('"');
            Results.Add("Command Name : " + CommnadName);
            keyval = args[1];
            base.CreateTask(() =>
            {
                string[] keyvalue = keyval.Trim().Split('=');
                if (keyvalue.Length == 2 && keyvalue[0][0] != '#')
                {
                    string key = keyvalue[0].Trim();
                    string val = keyvalue[1].Trim();
                    ApplicationConfiguration.Set(key, val);
                    Results.WriteKeyPair(key, val);
                }
                else
                {
                    Results.WriteLine("cant parse {0}", keyval);
                }
            });
        }
    }
}
